<?php

class ObservationController extends BackendController
{

    public $layout='/layouts/column2';
    public $city_en;
    public function actionChildPoint()
    {
        header("Content-type: text/html; charset=utf-8");
        $pid = intval(Yii::app()->request->getParam('pid'));
        $pinfo = OpenPoint::model()->findByPk($pid);
        $model = new OpenPoint();
        $criteria = new CDbCriteria;
        $criteria->order = "id DESC";
        $criteria->addCondition("pid=$pid");
        $dataProvider= new CActiveDataProvider($model, array(
            'criteria' => $criteria,
            'pagination'=>array(
                'pageSize'=>40,
            ),
        ));
        $this->render('child_point',array('pinfo'=>$pinfo,'dataProvider'=>$dataProvider));
    }
    public function actionChildPointAdd(){
        $model = new OpenPoint();
        if(Yii::app()->request->isPostRequest){
            $pid = intval($_POST['OpenPoint']['pid']);
            $pinfo = OpenPoint::model()->findByPk($pid);
            $_POST['OpenPoint']['create_time'] = time();
            $quanzhong = intval($_POST['OpenPoint']['point']);
            if($quanzhong >$pinfo->point){
                $data['status'] = 0;
                $data['message'] = '权重不得大于父类权重';
                echo json_encode($data);
                Yii::app()->end();
            }
            $jiaDb = Yii::app()->db->createCommand("SELECT SUM(point) as count FROM {{open_point}} WHERE pid=$pid")->queryRow();

            if(($jiaDb['count']+$quanzhong)>$pinfo->point){
                $a = $pinfo->point-$jiaDb['count'];
                $data['status'] = 0;
                $data['message'] = '二级分类权重数不得大于父类权重，您最多还能分配'.$a.'权重';
                echo json_encode($data);
                Yii::app()->end();
            }
            $model->setAttributes($_POST['OpenPoint']);
            if($model->save()){
                $data['status'] = 1;
                $data['message'] = '发布分类成功';
            }else{
                $data['status'] = 0;
                $data['message'] = $this->showError($model->getErrors());
            }
            echo json_encode($data);
            Yii::app()->end();
        }else{
            $pid = intval(Yii::app()->request->getParam('pid'));
            $pinfo = OpenPoint::model()->findByPk($pid);
            Yii::app()->clientScript->registerScriptFile($this->adminPath . '/js/jquery.min.js',CClientScript::POS_HEAD);
            $this->layout = '/layouts/dialog';
            $this->render('child_point_add',array('pinfo'=>$pinfo));
        }
    }
    public function actionChildPointUpdate(){
        $id = Yii::app()->request->getParam('id');
        Yii::app()->clientScript->registerScriptFile($this->adminPath . '/js/jquery.min.js',CClientScript::POS_HEAD);
        //获取区域
        $info = OpenPoint::model()->findByPk($id);
        if(Yii::app()->request->isPostRequest){
            if($info){
                $pid = intval($info->pid);
                $pinfo = OpenPoint::model()->findByPk($pid);
                $quanzhong = intval($_POST['OpenPoint']['point']);
                if($quanzhong >$pinfo->point){
                    $data['status'] = 0;
                    $data['message'] = '权重不得大于父类权重';
                    echo json_encode($data);
                    Yii::app()->end();
                }
                $jiaDb = Yii::app()->db->createCommand("SELECT SUM(point) as count FROM {{open_point}} WHERE pid=$pid")->queryRow();


                if(($jiaDb['count']-$info->point)+$quanzhong > $pinfo->point){
                    $a = $pinfo->point-$jiaDb['count'];
                    $data['status'] = 0;
                    $data['message'] = '二级分类权重数不得大于父类权重';
                    echo json_encode($data);
                    Yii::app()->end();
                }
                $info->setAttributes($_POST['OpenPoint']);
                if($info->update()){
                    //写入周边
                    $data['status'] = 1;
                    $data['message'] = '修改成功';
                }else{
                    $data['status'] = 0;
                    $data['message'] = $this->showError($info->getErrors());
                }
            }else{
                $data['status'] = 0;
                $data['message'] = '你无权作此操作';
            }

            echo json_encode($data);
            Yii::app()->end();
        }

        $this->layout = '/layouts/dialog';
        $this->render('child_point_update',array('info'=>$info));
    }
    public function actionPoint()
    {
        header("Content-type: text/html; charset=utf-8");
        $model = new OpenPoint();
        $criteria = new CDbCriteria;
        $criteria->order = "id DESC";
        $criteria->addCondition("pid=0");
        $dataProvider= new CActiveDataProvider($model, array(
            'criteria' => $criteria,
            'pagination'=>array(
                'pageSize'=>40,
            ),
        ));
        $this->render('point',array('dataProvider'=>$dataProvider));
    }
    public function actionPointAdd(){
        $model = new OpenPoint();
        if(Yii::app()->request->isPostRequest){
            $_POST['OpenPoint']['create_time'] = time();
            $_POST['OpenPoint']['pid'] = 0;
            $quanzhong = intval($_POST['OpenPoint']['point']);
            if($quanzhong >100){
                $data['status'] = 0;
                $data['message'] = '权重不得大于100';
                echo json_encode($data);
                Yii::app()->end();
            }
            $jiaDb = Yii::app()->db->createCommand("SELECT SUM(point) as count FROM {{open_point}} WHERE pid=0")->queryRow();

            if(($jiaDb['count']+$quanzhong)>100){
                $a = 100-$jiaDb['count'];
                $data['status'] = 0;
                $data['message'] = '大分类权重数不得大于100，您最多还能分配'.$a.'权重';
                echo json_encode($data);
                Yii::app()->end();
            }
            $model->setAttributes($_POST['OpenPoint']);
            if($model->save()){
                $data['status'] = 1;
                $data['message'] = '发布分类成功';
            }else{
                $data['status'] = 0;
                $data['message'] = $this->showError($model->getErrors());
            }
            echo json_encode($data);
            Yii::app()->end();
        }else{
            Yii::app()->clientScript->registerScriptFile($this->adminPath . '/js/jquery.min.js',CClientScript::POS_HEAD);
            $this->layout = '/layouts/dialog';
            $this->render('point_add');
        }
    }
    public function actionPointUpdate(){
        $id = Yii::app()->request->getParam('id');
        Yii::app()->clientScript->registerScriptFile($this->adminPath . '/js/jquery.min.js',CClientScript::POS_HEAD);
        //获取区域
        $info = OpenPoint::model()->findByPk($id);
        if(Yii::app()->request->isPostRequest){
            if($info){
                $quanzhong = intval($_POST['OpenPoint']['point']);
                if($quanzhong >100){
                    $data['status'] = 0;
                    $data['message'] = '权重不得大于100';
                    echo json_encode($data);
                    Yii::app()->end();
                }
                $jiaDb = Yii::app()->db->createCommand("SELECT SUM(point) as count FROM {{open_point}} WHERE pid=0")->queryRow();

                if((($jiaDb['count']-$info->point)+$quanzhong)>100){
                    $a = 100-$jiaDb['count'];
                    $data['status'] = 0;
                    $data['message'] = '大分类权重数不得大于100，您最多还能分配'.$a.'权重';
                    echo json_encode($data);
                    Yii::app()->end();
                }
                $info->setAttributes($_POST['OpenPoint']);
                if($info->update()){
                    //写入周边
                    $data['status'] = 1;
                    $data['message'] = '修改成功';
                }else{
                    $data['status'] = 0;
                    $data['message'] = $this->showError($info->getErrors());
                }
            }else{
                $data['status'] = 0;
                $data['message'] = '你无权作此操作';
            }

            echo json_encode($data);
            Yii::app()->end();
        }

        $this->layout = '/layouts/dialog';
        $this->render('point_update',array('info'=>$info));
    }
    public function actionPointDelete(){
        $id = Yii::app()->request->getParam('id');
        $info = OpenPoint::model()->findByPk($id);
        if($info){
            $ok = $info->delete();
            if($ok){
                $data['status'] = 1;
                $data['message'] = '删除数据成功';
            }else{
                $data['status'] = 0;
                $data['message'] = '删除数据失败';
            }

        }else{
            $data['status'] = 0;
            $data['message'] = '你无权作此操作';
        }
        echo json_encode($data);
        Yii::app()->end();
    }




    public function actionHuman()
    {
        header("Content-type: text/html; charset=utf-8");
        $model = new Human();
        $criteria = new CDbCriteria;
        $criteria->order = "id DESC";
        $dataProvider= new CActiveDataProvider($model, array(
            'criteria' => $criteria,
            'pagination'=>array(
                'pageSize'=>40,
            ),
        ));
        $this->render('human',array('dataProvider'=>$dataProvider));

    }
    public function actionOpenComment()
    {
        header("Content-type: text/html; charset=utf-8");
        $model = new OpenComment();
        $criteria = new CDbCriteria;
        $criteria->order = "id DESC";
        $dataProvider= new CActiveDataProvider($model, array(
            'criteria' => $criteria,
            'pagination'=>array(
                'pageSize'=>40,
            ),
        ));
        $this->render('comment',array('dataProvider'=>$dataProvider));
    }
    public function actionCommentUpdate(){
        $id = Yii::app()->request->getParam('id');
        Yii::app()->clientScript->registerScriptFile($this->adminPath . '/js/jquery.min.js',CClientScript::POS_HEAD);
        //获取区域
        $info = OpenComment::model()->findByPk($id);
        if(Yii::app()->request->isPostRequest){
            if($info){
                $_POST['OpenComment']['text'] = trim($_POST['OpenComment']['text']);
                $info->setAttributes($_POST['OpenComment']);
                if($info->update()){
                    //写入周边
                    $data['status'] = 1;
                    $data['message'] = '评论修改成功';
                }else{
                    $data['status'] = 0;
                    $data['message'] = $this->showError($info->getErrors());
                }
            }else{
                $data['status'] = 0;
                $data['message'] = '你无权作此操作';
            }

            echo json_encode($data);
            Yii::app()->end();
        }


        $this->layout = '/layouts/dialog';
        $this->render('comment_update',array('info'=>$info));
    }
    public function actionCommentDelete(){
        $id = Yii::app()->request->getParam('id');
        $info = OpenComment::model()->findByPk($id);
        if($info){
            $ok = $info->delete();
            if($ok){
                $data['status'] = 1;
                $data['message'] = '删除数据成功';
            }else{
                $data['status'] = 0;
                $data['message'] = '删除数据失败';
            }

        }else{
            $data['status'] = 0;
            $data['message'] = '你无权作此操作';
        }
        echo json_encode($data);
        Yii::app()->end();
    }


    public function actionHumanAdd(){
        if(Yii::app()->request->isPostRequest){
            $model = new Human();
            $_POST['Human']['user_name'] = trim($_POST['Human']['user_name']);
            $_POST['Human']['key_sn'] = trim($_POST['Human']['key_sn']);
            $_POST['Human']['role'] = 3;
            $model->setAttributes($_POST['Human']);
            if($model->save()){
                $data['status'] = 1;
                $data['message'] = '发布专家成功';
            }else{
                $data['status'] = 0;
                $data['message'] = $this->showError($model->getErrors());
            }
            echo json_encode($data);
            Yii::app()->end();
        }else{
            Yii::app()->clientScript->registerScriptFile($this->adminPath . '/js/jquery.min.js',CClientScript::POS_HEAD);
            $this->layout = '/layouts/dialog';
            $this->render('human_add');

        }
    }
    public function actionHumanUpdate(){
        $id = Yii::app()->request->getParam('id');
        Yii::app()->clientScript->registerScriptFile($this->adminPath . '/js/jquery.min.js',CClientScript::POS_HEAD);
        //获取区域
        $info = Human::model()->findByPk($id);
        if(Yii::app()->request->isPostRequest){
            if($info){
                $_POST['Human']['user_name'] = trim($_POST['Human']['user_name']);
                $_POST['Human']['key_sn'] = trim($_POST['Human']['key_sn']);
                $info->setAttributes($_POST['Human']);
                if($info->update()){
                    //写入周边
                    $data['status'] = 1;
                    $data['message'] = '专家修改成功';
                }else{
                    $data['status'] = 0;
                    $data['message'] = $this->showError($info->getErrors());
                }
            }else{
                $data['status'] = 0;
                $data['message'] = '你无权作此操作';
            }

            echo json_encode($data);
            Yii::app()->end();
        }


        $this->layout = '/layouts/dialog';
        $this->render('human_update',array('info'=>$info));
    }
    public function actionHumanDelete(){
        $id = Yii::app()->request->getParam('id');
        $info = Human::model()->findByPk($id);
        if($info){
            $ok = $info->delete();
            if($ok){
                $data['status'] = 1;
                $data['message'] = '删除数据成功';
            }else{
                $data['status'] = 0;
                $data['message'] = '删除数据失败';
            }

        }else{
            $data['status'] = 0;
            $data['message'] = '你无权作此操作';
        }
        echo json_encode($data);
        Yii::app()->end();
    }

    public function actionPinglun(){
        header("Content-type: text/html; charset=utf-8");
        $id = Yii::app()->request->getParam('id');
        $open_info = Open::model()->findByPk($id);
        $zjstr = $open_info->zid;
        $tkstr = $open_info->lid;
        if($zjstr){
            $zjinfo = Yii::app()->db->createCommand("SELECT * FROM (SELECT t1.user_name,t1.id FROM tbl_human t1 WHERE role=3 AND id IN($zjstr)) t3 LEFT JOIN (SELECT t2.text,t2.uid FROM tbl_open_comment t2 WHERE t2.oid=$id AND t2.type=2) t4 ON t3.id=t4.uid")->queryAll();

        }else{
            $zjinfo = '';
        }
        if($tkstr){
            $tkinfo = Yii::app()->db->createCommand("SELECT * FROM (SELECT t1.user_name,t1.id FROM tbl_people t1 WHERE role=3 AND id IN($tkstr)) t3 LEFT JOIN (SELECT t2.text,t2.uid FROM tbl_open_comment t2 WHERE t2.oid=$id AND t2.type=1) t4 ON t3.id=t4.uid")->queryAll();
        }else{
            $tkinfo = '';
        }

        $this->render('pinglun',array('id'=>$id,'zjinfo'=>$zjinfo,'tkinfo'=>$tkinfo));
    }
    public function actionExcelPingLun(){
        $id = Yii::app()->request->getParam('id');
        $open_info = Open::model()->findByPk($id);
        $zjstr = $open_info->zid;
        $tkstr = $open_info->lid;
        if($zjstr){
            $zjinfo = Yii::app()->db->createCommand("SELECT * FROM (SELECT t1.user_name,t1.id FROM tbl_human t1 WHERE role=3 AND id IN($zjstr)) t3 LEFT JOIN (SELECT t2.text,t2.uid FROM tbl_open_comment t2 WHERE t2.oid=$id AND t2.type=2) t4 ON t3.id=t4.uid")->queryAll();
        }else{
            $zjinfo = '';
        }
        if($tkstr){
            $tkinfo = Yii::app()->db->createCommand("SELECT * FROM (SELECT t1.user_name,t1.id FROM tbl_people t1 WHERE role=3 AND id IN($tkstr)) t3 LEFT JOIN (SELECT t2.text,t2.uid FROM tbl_open_comment t2 WHERE t2.oid=$id AND t2.type=1) t4 ON t3.id=t4.uid")->queryAll();
        }else{
            $tkinfo = '';
        }

        $str = '';
        if($zjinfo){
            $aaa = "专家姓名\t";
            $aaa .= "评论\t";
            $aaa .= "\n";
            $str .= iconv('utf-8','gb2312',$aaa);
            foreach ($zjinfo as $v) {
                $sn = iconv('utf-8','gb2312',$v['user_name']);
                $str .= $sn."\t";
                if($v['text']){
                    $name = iconv('utf-8','gb2312',$v['text']);
                    $str .= $name."\t";
                }else{
                    $name = iconv('utf-8','gb2312','未评论');
                    $str .= $name."\t";
                }
                $str .= "\n";
            }
        }
        if($tkinfo){
            $bbb = "老师姓名\t";
            $bbb .= "评论\t";
            $bbb .= "\n";
            $str .= iconv('utf-8','gb2312',$bbb);
            foreach ($tkinfo as $vv) {
                $sn = iconv('utf-8','gb2312',$vv['user_name']);
                $str .= $sn."\t";
                if($vv['text']){
                    $name = iconv('utf-8','gb2312',$vv['text']);
                    $str .= $name."\t";
                }else{
                    $name = iconv('utf-8','gb2312','未评论');
                    $str .= $name."\t";
                }
                $str .= "\n";
            }
        }
        $filename = $open_info->title.'pinglun.xls';
        $this->export_excel($filename, $str);
    }
    private function export_excel($filename,$content) {
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Content-Type: application/vnd.ms-execl");
        header("Content-Type: application/force-download");
        header("Content-Type: application/download");
        header("Content-Disposition: attachment; filename=".$filename);
        header("Content-Transfer-Encoding: binary");
        header("Pragma: no-cache");
        header("Expires: 0");

        echo $content;
    }
    public function actionExcelPingFen(){
        $id = Yii::app()->request->getParam('id');
        $open_info = Open::model()->findByPk($id);
        $zjstr = $open_info->zid;
        $tkstr = $open_info->lid;


        if($zjstr){
            $zjinfo = Yii::app()->db->createCommand("SELECT t1.user_name,t1.id FROM tbl_human t1 WHERE role=3 AND id IN($zjstr)")->queryAll();
        }else{
            $zjinfo = '';
        }
        if($tkstr){
            $tkinfo = Yii::app()->db->createCommand("SELECT t1.user_name,t1.id FROM tbl_people t1 WHERE role=3 AND id IN($tkstr)")->queryAll();
        }else{
            $tkinfo = '';
        }
            $str = '';
        if($zjinfo){
            foreach($zjinfo as $v){
                $aaa = "专家-".$v['user_name']."\t";
                $aaa .= "-\t";
                $aaa .= "\n";
                $str .= iconv('utf-8','gb2312',$aaa);
                $p_info = OpenPoint::model()->findAll('pid=:pid',array(':pid'=>0));
                if($p_info){
                    foreach($p_info as $vv){
                        $bbb = $vv->title."\t";
                        $bbb .= "评星\t";
                        $bbb .= "\n";
                        $str .= iconv('utf-8','gb2312',$bbb);
                        $c_info = OpenPoint::model()->findAll('pid=:pid',array(':pid'=>$vv->id));
                        if($c_info){
//                            $x_info = OpenStart::model()->count('oid=:oid and pid=:pid and uid=:uid and type=:type',
//                                array(
//                                    ':oid'=>$id,
//                                    ':pid'=>$vv->id,
//                                    ':uid'=>$v['id'],
//                                    ':type'=>2,
//                                ));
//                            $connection=Yii::app()->db;
//                            $command=$connection->createCommand("SELECT SUM(start) FROM {{open_start}} where
//                            oid=$id and pid=$vv->id and uid=".$v['id']." and type=2");
//                            $csum = $command->queryRow();
//                            $xxx = $vv->title."\t";




                            foreach($c_info as $vvv){
                                $ccc = $vvv->title."\t";
                                $s_info = OpenStart::model()->find('oid=:oid and pid=:pid and uid=:uid and type=:type and opid=:opid',
                                    array(
                                        ':oid'=>$id,
                                        ':pid'=>$vv->id,
                                        ':uid'=>$v['id'],
                                        ':type'=>2,
                                        ':opid'=>$vvv->id,
                                    ));
                                if($s_info){
                                    $ccc .= $s_info->start."\t";
                                }else{
                                    $ccc .= "-\t";
                                }
                                $ccc .= "\n";
                                $str .= iconv('utf-8','gb2312',$ccc);
                            }
                        }
                    }
                }
                $str .= "\n";
            }
        }
        $str .= "\n";
        $str .= "\n";
        $str .= "\n";

        if($tkinfo){
            foreach($tkinfo as $v){
                $aaa = "老师-".$v['user_name']."\t";
                $aaa .= "-\t";
                $aaa .= "\n";
                $str .= iconv('utf-8','gb2312',$aaa);
                $p_info = OpenPoint::model()->findAll('pid=:pid',array(':pid'=>0));
                if($p_info){
                    foreach($p_info as $vv){
                        $bbb = $vv->title."\t";
                        $bbb .= "评星\t";
                        $bbb .= "\n";
                        $str .= iconv('utf-8','gb2312',$bbb);
                        $c_info = OpenPoint::model()->findAll('pid=:pid',array(':pid'=>$vv->id));
                        if($c_info){
                            foreach($c_info as $vvv){
                                $ccc = $vvv->title."\t";
                                $s_info = OpenStart::model()->find('oid=:oid and pid=:pid and uid=:uid and type=:type and opid=:opid',
                                    array(
                                        ':oid'=>$id,
                                        ':pid'=>$vv->id,
                                        ':uid'=>$v['id'],
                                        ':type'=>1,
                                        ':opid'=>$vvv->id,
                                    ));
                                if($s_info){
                                    $ccc .= $s_info->start."\t";
                                }else{
                                    $ccc .= "-\t";
                                }
                                $ccc .= "\n";
                                $str .= iconv('utf-8','gb2312',$ccc);
                            }
                        }
                    }
                }
                $str .= "\n";
            }
        }
        $filename = $open_info->title.'pingfen.xls';
        $this->export_excel($filename, $str);
    }
    public function actionPingfen(){
        header("Content-type: text/html; charset=utf-8");
        $id = Yii::app()->request->getParam('id');
        $open_info = Open::model()->findByPk($id);
        $zjstr = $open_info->zid;
        $tkstr = $open_info->lid;
        if($zjstr){
            $zjinfo = Yii::app()->db->createCommand("SELECT t1.user_name,t1.id FROM tbl_human t1 WHERE role=3 AND id IN($zjstr)")->queryAll();
        }else{
            $zjinfo = '';
        }
        if($tkstr){
            $tkinfo = Yii::app()->db->createCommand("SELECT t1.user_name,t1.id FROM tbl_people t1 WHERE role=3 AND id IN($tkstr)")->queryAll();
        }else{
            $tkinfo = '';
        }



        $this->render('pingfen',array('zjinfo'=>$zjinfo,'tkinfo'=>$tkinfo,'id'=>$id));
    }
    public function actionOpen()
    {
        header("Content-type: text/html; charset=utf-8");
        $model = new Open();
        $criteria = new CDbCriteria;
        $criteria->order = "id DESC";
        $dataProvider= new CActiveDataProvider($model, array(
            'criteria' => $criteria,
            'pagination'=>array(
                'pageSize'=>40,
            ),
        ));
        $this->render('open',array('dataProvider'=>$dataProvider));
    }
    public function actionOpenAdd(){
        $model = new Open();
        if(Yii::app()->request->isPostRequest){
            $_POST['Open']['status'] = 0;
            $_POST['Open']['create_time'] = time();
            $_POST['Open']['start_time'] = strtotime($_POST['Open']['start_time']);
            $_POST['Open']['end_time'] = strtotime($_POST['Open']['end_time']);
            $_POST['Open']['gid'] = implode(",",$_POST['guancha']);
            $_POST['Open']['lid'] = implode(",",$_POST['tingke']);
            $_POST['Open']['zid'] = implode(",",$_POST['zhuanjia']);
            $_POST['Open']['open_time'] = intval($_POST['Open']['open_time']);
            $model->setAttributes($_POST['Open']);
            if($model->save()){
                $data['status'] = 1;
                $data['message'] = '发布公开课成功';
            }else{
                $data['status'] = 0;
                $data['message'] = $this->showError($model->getErrors());
            }
            echo json_encode($data);
            Yii::app()->end();
        }else{
            //获取老师数据
            $techer = People::model()->findAll('role=:role',array(':role'=>3));
            $zhuanjia = Human::model()->findAll('role=:role',array(':role'=>3));
            Yii::app()->clientScript->registerScriptFile($this->adminPath . '/js/jquery.min.js',CClientScript::POS_HEAD);
            $this->layout = '/layouts/dialog';
            $this->render('open_add',array('techer'=>$techer,'zhuanjia'=>$zhuanjia));
        }
    }

    public function actionOpenUpdate(){
        $id = Yii::app()->request->getParam('id');
        Yii::app()->clientScript->registerScriptFile($this->adminPath . '/js/jquery.min.js',CClientScript::POS_HEAD);
        //获取区域
        $info = Open::model()->findByPk($id);
        if(Yii::app()->request->isPostRequest){
            if($info){
                $_POST['Open']['start_time'] = strtotime($_POST['Open']['start_time']);
                $_POST['Open']['end_time'] = strtotime($_POST['Open']['end_time']);
                $_POST['Open']['gid'] = implode(",",$_POST['guancha']);
                $_POST['Open']['lid'] = implode(",",$_POST['tingke']);
                $_POST['Open']['zid'] = implode(",",$_POST['zhuanjia']);
                $_POST['Open']['open_time'] = intval($_POST['Open']['open_time']);
                $info->setAttributes($_POST['Open']);
                if($info->update()){
                    //写入周边
                    $data['status'] = 1;
                    $data['message'] = '公开课修改成功';
                }else{
                    $data['status'] = 0;
                    $data['message'] = $this->showError($info->getErrors());
                }
            }else{
                $data['status'] = 0;
                $data['message'] = '你无权作此操作';
            }

            echo json_encode($data);
            Yii::app()->end();
        }

        $techer = People::model()->findAll('role=:role',array(':role'=>3));
        $zhuanjia = Human::model()->findAll('role=:role',array(':role'=>3));
        $info->start_time = date('Y-m-d H:i:s',$info->start_time);
        $info->end_time = date('Y-m-d H:i:s',$info->end_time);
        $this->layout = '/layouts/dialog';
        $this->render('open_update',array('techer'=>$techer,'zhuanjia'=>$zhuanjia,'info'=>$info));
    }
    public function actionOpenDelete(){
        $id = Yii::app()->request->getParam('id');
        $info = Open::model()->findByPk($id);
        if($info){
            $ok = $info->delete();
            if($ok){
                $data['status'] = 1;
                $data['message'] = '删除数据成功';
            }else{
                $data['status'] = 0;
                $data['message'] = '删除数据失败';
            }

        }else{
            $data['status'] = 0;
            $data['message'] = '你无权作此操作';
        }
        echo json_encode($data);
        Yii::app()->end();
    }
}